package com.kawaiior.asoulworld.item.misc.arrow;

import com.kawaiior.asoulworld.item.ItemBase;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

import javax.annotation.Nonnull;


public class ItemDianaCandy extends ItemBase {

    public ItemDianaCandy(String name) {
        super(name);
    }

    @Nonnull
    @Override
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
        ItemStack stack = player.getHeldItem(hand);
        if (!world.isRemote)
        {
            if (player.getFoodStats().getFoodLevel()<20)
            {
                int foodlevel = player.getFoodStats().getFoodLevel();
                int i = Math.min(foodlevel + 1, 20);
                player.getFoodStats().setFoodLevel(i);
                player.heal(4f);
                EntityUtil.ApplyBuff(player, MobEffects.FIRE_RESISTANCE,0,30);
//                stack.setCount(stack.getCount()-1);
                stack.shrink(1);
                //测试用代码
//                EntityUtil.ApplyBuff(player, ModPotions.AS_BREAK_DEFENSE,0,30);
                return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
            }
            return ActionResult.newResult(EnumActionResult.PASS, stack);
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
    }
}
